﻿<template>
  <a-modal
    :title="title"
    width="70%"
    :visible="visible"
    :confirmLoading="loading"
    @ok="handleSubmit"
    @cancel="()=>{this.visible=false}"
  >
    <a-spin :spinning="loading">
      <a-form-model ref="form" :model="entity" :rules="rules" v-bind="layout">
        <a-form-model-item label="客户ID" prop="MID">
         <a-select
                allowClear
                show-search
                v-model="entity.MID"
                @change="MerchantChange"
                placeholder="请选择客户"
              >
                <a-select-option v-for="(item, index) in MerchantList" :key="index" :value="item.value">
                  {{ item.text }}
                </a-select-option>
              </a-select>
        </a-form-model-item>
        <a-form-model-item label="税号" prop="TaxRegistrationNo">
          <a-input v-model="entity.TaxRegistrationNo" autocomplete="off" />
        </a-form-model-item>
        <a-form-model-item label="电话" prop="RegisteredTelephone">
          <a-input v-model="entity.RegisteredTelephone" autocomplete="off" />
        </a-form-model-item>
        <a-form-model-item label="地址" prop="RegisteredAddr">
          <a-input v-model="entity.RegisteredAddr" autocomplete="off" />
        </a-form-model-item>
        <a-form-model-item label="银行" prop="DepositBank">
          <a-input v-model="entity.DepositBank" autocomplete="off" />
        </a-form-model-item>
        <a-form-model-item label="账号" prop="BankAccount">
          <a-input v-model="entity.BankAccount" autocomplete="off" />
        </a-form-model-item>
      </a-form-model>
    </a-spin>
  </a-modal>
</template>

<script>
export default {
  props: {
    parentObj: Object
  },
  data() {
    return {
      MerchantList:[],
      layout: {
        labelCol: { span: 5 },
        wrapperCol: { span: 18 }
      },
      visible: false,
      loading: false,
      entity: {},
      rules: {},
      title: ''
    }
  },
  methods: {
    MerchantChange(value){
      let obj = {};
         obj = this.MerchantList.find((item)=>{ //这里的Data就是上面遍历的数据源
           return item.Id === value; //筛选出匹配数据
         });
         console.log(obj)
      this.entity.InvoiceRise = obj.text
    },
    async GetMerchant() {
      await this.$http.post('/Base_Manage/Home/GetMerchant_Select').then((res) => {
        this.MerchantList = res.Data
      })
    },
    init() {
      this.GetMerchant()
      this.title = "新增"
      this.visible = true
      this.entity = {}
      this.$nextTick(() => {
        this.$refs['form'].clearValidate()
      })
    },
    openForm(id, title) {
      this.init()

      if (id) {
        this.title = "修改"
        this.loading = true
        this.$http.post('/Base_leasesystem_invoiceinformation/leasesystem_invoiceinformation/GetTheData', { id: id }).then(resJson => {
          this.loading = false

          this.entity = resJson.Data
        })
      }
    },
    handleSubmit() {
      this.$refs['form'].validate(valid => {
        if (!valid) {
          return
        }
        this.loading = true
        this.$http.post('/Base_leasesystem_invoiceinformation/leasesystem_invoiceinformation/SaveData', this.entity).then(resJson => {
          this.loading = false

          if (resJson.Success) {
            this.$message.success('操作成功!')
            this.visible = false

            this.parentObj.GetInvoiceHead(this.entity)
          } else {
            this.$message.error(resJson.Msg)
          }
        })
      })
    }
  }
}
</script>
